
CREATE TABLE Developer
(
	IdD smallint  NOT NULL ,
	FirstNameD varchar(20)  NULL ,
	SecondNameD varchar(20)  NULL ,
	BirthdayD datetime  NULL ,
	SalaryD smallint  NULL ,
	TelephoneNumberD smallint  NULL 
)
go


ALTER TABLE Developer
	ADD CONSTRAINT XPKDeveloper PRIMARY KEY  NONCLUSTERED (IdD ASC)
go


CREATE TABLE Error
(
	IdE smallint  NOT NULL ,
	DescriptionE varchar(20)  NULL ,
	TimeDetectionE datetime  NULL ,
	PriorityE smallint  NULL 
)
go


ALTER TABLE Error
	ADD CONSTRAINT XPKError PRIMARY KEY  NONCLUSTERED (IdE ASC)
go


CREATE TABLE Module
(
	Who_is_developer smallint  NOT NULL ,
	IdM smallint  NOT NULL ,
	NameM varchar(20)  NULL ,
	PurposeM varchar(20)  NULL ,
	OpennessCodeM varbinary  NULL ,
	PriorityM smallint  NULL 
)
go


ALTER TABLE Module
	ADD CONSTRAINT XPKModule PRIMARY KEY  NONCLUSTERED (IdM ASC)
go


CREATE TABLE Program
(
	NameP varchar(20)  NULL ,
	IdP smallint  NOT NULL ,
	PriceP smallint  NULL ,
	SiteP varchar(20)  NULL ,
	AboutP varchar(20)  NULL 
)
go


ALTER TABLE Program
	ADD CONSTRAINT XPKProgram PRIMARY KEY  NONCLUSTERED (IdP ASC)
go


CREATE TABLE Program_Module_Error
(
	What_error_contains smallint  NOT NULL ,
	Which_module_contains_it smallint  NOT NULL ,
	Which_program_contains_it smallint  NOT NULL 
)
go


ALTER TABLE Program_Module_Error
	ADD CONSTRAINT XPKProgram_Module_Error PRIMARY KEY  CLUSTERED (What_error_contains ASC,Which_module_contains_it ASC,Which_program_contains_it ASC)
go



ALTER TABLE Module
	ADD CONSTRAINT  R_2 FOREIGN KEY (Who_is_developer) REFERENCES Developer(IdD)
		ON DELETE NO ACTION
		ON UPDATE NO ACTION
go



ALTER TABLE Program_Module_Error
	ADD CONSTRAINT  R_6 FOREIGN KEY (What_error_contains) REFERENCES Error(IdE)
		ON DELETE NO ACTION
		ON UPDATE NO ACTION
go

ALTER TABLE Program_Module_Error
	ADD CONSTRAINT  R_4 FOREIGN KEY (Which_module_contains_it) REFERENCES Module(IdM)
		ON DELETE NO ACTION
		ON UPDATE NO ACTION
go

ALTER TABLE Program_Module_Error
	ADD CONSTRAINT  R_10 FOREIGN KEY (Which_program_contains_it) REFERENCES Program(IdP)
		ON DELETE NO ACTION
		ON UPDATE NO ACTION
go

